import axios from "axios";
// import qs from "qs";
import { prefix, postheaders } from "./index";

export const getItems = async (param) => {
  let response = await axios({
    method: "get",
    url: prefix + "/cart_item",
    // postheaders,
    params: {
      type: param.type,
      value: param.value,
      page: param.page,
      size: param.size,
    },
  });

  return response;
};
export const getItem = async (params) => {
  let response = await axios({
    method: "get",
    url: prefix + "/cart_item" + "/" + params,
    // postheaders,
  });
  return response;
};
export const addCartItem = async (param) => {
  let response = await axios({
    method: "post",
    postheaders,
    url: prefix + "/cart",
    data: {
      userId: param.userId,
      typeCode: param.typeCode,
      cartItemDO: param.item,
      buyItemNum: param.buyNum,
    },
  });
  console.log(response)
  return response;
};
export const getCartOrder = async (userId) => {
  console.log(userId)
  let response = await axios({
    method: "get",
    url: prefix + "/cart" + "/" + userId,
  });

  return response;
};
export const clearCart = async (userId) => {
  let response = await axios({
    method: "delete",
    url: prefix + "/cart" + "/" + userId,
  });

  return response;
};

export const updateCart = async (param) => {

  let response = await axios({
    method: "put",
    postheaders,
    url: prefix + "/cart",
    data: {
      userId: param.userId,
      typeCode: param.typeCode,
      cartItemDO: param.item,
      buyItemNum: param.buyNum,
    },
  });
  return response;
};
// export const deleteUser = async (userId) => {

//   let response = await axios({
//     method: "post",
//     postheaders,
//     url: prefix + "/user/delete",
//     data: qs.stringify({
//       userId
//     }),

//   });
//   return response;
// };
